package com.coocaa.typhoon.api.v1.milvus;

import com.coocaa.cirrus.common.base.model.RespBase;
import com.coocaa.typhoon.api.v1.milvus.model.UserFileMilvusVO;
import com.coocaa.typhoon.api.v1.milvus.service.UserFileCollectionCreateService;
import com.coocaa.typhoon.api.v1.milvus.service.UserFileMilvusQueryService;
import com.coocaa.typhoon.api.v1.milvus.service.sync.InitSyncService;
import com.coocaa.typhoon.api.v1.milvus.service.sync.UserFileSyncService;
import com.coocaa.typhoon.api.v1.mysql.model.entity.UserFileEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author bijiahao
 * @date : 2025/9/25 10:11
 * @description
 */
@RestController
@RequestMapping("/v1/milvus")
@Tag(name = "Milvus测试")
public class TestMilvusController {
    @Autowired
    private UserFileSyncService userFileSyncService;
    @Autowired
    private UserFileMilvusQueryService userFileMilvusQueryService;
    @Autowired
    private UserFileCollectionCreateService userFileCollectionCreateService;
    @Autowired
    private InitSyncService initSyncService;

    @Operation(summary = "测试查询")
    @GetMapping(value = "/hybridSearch")
    @Parameters({
            @Parameter(name = "userId", example = "", description = "用户ID"),
            @Parameter(name = "text", example = "查询下我的宠物", description = "文本查询"),
            @Parameter(name = "top", example = "10", description = "查询数量"),
            @Parameter(name = "fileTypeList", example = "PNG", description = "文件类型"),
            @Parameter(name = "location", example = "广州", description = "地点"),
            @Parameter(name = "tosLinkList", example = "", description = "TOS链接"),
            @Parameter(name = "startTime", example = "", description = "开始时间"),
            @Parameter(name = "endTime", example = "", description = "结束时间"),
    })
    public RespBase<List<UserFileMilvusVO>> hybridSearch(@RequestParam String userId,
                                                         @RequestParam String text,
                                                         @RequestParam Integer top,
                                                         @RequestParam(required = false) List<String> fileTypeList,
                                                         @RequestParam(required = false) String location,
                                                         @RequestParam(required = false) List<String> tosLinkList,
                                                         @RequestParam(required = false) String startTime,
                                                         @RequestParam(required = false) String endTime) {
        List<UserFileMilvusVO> res = userFileMilvusQueryService.hybridSearch(userId, text, fileTypeList, location, top, tosLinkList, startTime, endTime);
        return new RespBase().setData(res).setSuccessResult();
    }

    @Operation(summary = "测试保存")
    @PostMapping(value = "/testSave")
    public RespBase testSave(@RequestBody UserFileEntity entity) {
        userFileSyncService.sync(entity);
        return new RespBase().setSuccessResult();
    }

    @Operation(summary = "测试创建")
    @PostMapping(value = "/testCreate")
    public RespBase testCreate(@RequestParam String collectionName) {
        userFileCollectionCreateService.create(collectionName);
        return new RespBase().setSuccessResult();
    }

    @Operation(summary = "测试初始")
    @PostMapping(value = "/testInit")
    public RespBase testInit(@RequestParam String userId) {
        initSyncService.init(userId);
        return new RespBase().setSuccessResult();
    }

}
